<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			function reg(){
			//0.收集填入的信息,	非空验证
			var $uname=uname.value;
			var $upwd=upwd.value;
			var $email=email.value;
			var $phone=phone.value;
			var $user_name=user_name.value;
			var $gender="保密";
			if(man.checked){
				$gender=1
			}else if(woman.checked){
				$gender=0
			}else{
				$gender=-1
			}
			if(!$uname){alert("网名不能为空");return}
			if(!$upwd){alert("密码不能为空");return}
			if(!$email){alert("邮件不能为空");return}
			if(!$phone){alert("手机号码不能为空");return}
			if(!$user_name){alert("用户名不能为空");return}
			//1.创建xhr异步对象
			var xhr=new XMLHttpRequest();
			//4.接收响应
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4 && xhr.status==200){
					var r=xhr.responseText;
					if(r==1){
						alert("注册成功")
					}else{
						alert("注册失败")
						//location.href="user_information_login.html";
					}
				}
			}
			//2.创建请求,打开连接
			xhr.open("POST",`/user/v1/reg`,true)
			//3.发送请求
			var formdata=`uname=${$uname}&upwd=${$upwd}&phone=${$phone}&email=${$email}&user_name=${$user_name}&gender=${$gender}`;
			console.log(formdata)
			xhr.setRequestHeader("content-type","application/x-www-form-urlencoded")
			xhr.send(formdata);
			}
		</script>
	</head>
	<body>
		<input type="text" id="uname" onblur="check()">网名<br>
		<input type="text" id="upwd">密码<br>
		<input type="text" id="email">邮件<br>
		<input type="text" id="phone">手机号码<br>
		<input type="text" id="user_name">用户名<br>
		<input type="radio" name="gender" checked id="man" />男
		<input type="radio" name="gender" id="woman" />女
		<input type="radio" name="gender" id="unk" />保密<br>
		<button onclick="reg()">注册</button>
	</body>
</html>
